package LC;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC6
 * @Description: TODO
 * @Author hl
 * @Date 2021/3/22
 * @Version V1.0
 **/
public class LC6 {
    public static String convert(String s, int numRows) {
        if(numRows<=1) return s;
        ArrayList<StringBuilder> list=new ArrayList<>();
        for(int i=0;i<numRows;i++){
            list.add(new StringBuilder());
        }
        int flag=-1,index=0;
        for(Character c:s.toCharArray()){
            if(index==0||index==numRows-1) flag=-flag;
            list.get(index).append(c);
            index=index+flag;
        }
        StringBuilder res=new StringBuilder();
        for(StringBuilder target:list){
            res.append(target);
        }
        return res.toString();
    }

    public static void main(String[] args) {
        System.out.println(convert("PAYPALISHIRING",3));
    }
}
